package main

import (
	"flag"
	"fmt"
	"user/initialized"
	"user/public"

	"user/internal/config"
	"user/internal/server"
	"user/internal/svc"
	"user/user"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

var configFile = flag.String("f", "etc/user.yaml", "the config file")

func main() {

	initialized.InitCfg() //初始化配置

	//initialized.Init_Consul() //初始化consul

	public.Database() //初始化database

	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)
	ctx := svc.NewServiceContext(c)
	//修改监听端口号
	//c.ListenOn = fmt.Sprintf("%s:%d", public.UserConfig.Server.Host, public.UserConfig.Server.Port)

	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		user.RegisterUserServer(grpcServer, server.NewUserServer(ctx))

		reflection.Register(grpcServer)
	})
	defer s.Stop()

	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
